<script setup lang="ts">

import { onMounted, reactive } from "vue";
import { useRouter, useRoute } from 'vue-router'
import { productDetail } from '@/apis/index'
import qStars from '@/components/qStars.vue'
const router = useRouter()
const route = useRoute()
const vdata = reactive({
    num: 1,
    goods: {}
})
onMounted(() => {
    getDeatail()
})
const getDeatail = () => {
    productDetail(route.query.id).then(res => {
        console.log(res.data)
        vdata.goods = res.data.data
    })
        .catch(err => console.log(err))
}
const addOrder = () => {
    router.push({
        path: 'toOrder',
        query: {
            ...vdata.goods,
            num: vdata.num,
        }
    })
}
const goods = {
    id: 1,
    goodsBanner: [],
    goods_name: '天堂伞',
    goods_brand: '晨风华容',
    category: '日用-雨具',
    chandd: '江苏',
    primary_price: 17,
    price: 15.5,
    goods_stock: 10,
    sku: 1646464,
    goods_details: '商品详情'
}
</script>
<template>
    <div style="width: 1200px; margin: 50px auto">
        <el-row :gutter="20">
            <el-col :span="16">
                <div class="good_name">{{ vdata.goods.goods_name }}</div>
                <div class="good_category"><span class="goods_brand">{{ vdata.goods.goods_brand }}</span>&nbsp;<span
                        class="category">{{ vdata.goods.category }}</span></div>
                <div class="good_price_content" style="display: flex;align-items: baseline">
                    <div class="small-text">￥</div>
                    <div class="price">{{ vdata.goods.primary_price }}</div>
                    <div class="small-text">起</div>
                    <div class="small-text goods_active">未打折扣或未提供满减服务</div>
                </div>
                <div class="goods_stock">
                    <div class="goods_price_title">库 存：</div>
                    {{ vdata.goods.goods_stock }}
                    <div v-if="goods.goods_stock * 1 == 0" style="
              margin-left: 10px;
              height: 50px;
              display: flex;
              align-items: center;
              color: #a2a2a2;
            ">
                        [<span style="color: #ff0000">无货</span>]暂时无货，等待卖家添加库存
                    </div>
                </div>
                <!-- <div class="goods_rank">
                    <div>累计销售 <span>0</span></div>
                    <div>累计评论 <span>0</span></div>
                    <div>收藏数 <span>0</span></div>
                </div> -->
                <div class="goods_service">
                    <div class="goods_price_title">源地址：</div>
                    {{ vdata.goods.chandd }}
                </div>
                <div class="goods_pay">
                    <div class="goods_price_title">商品编码：</div>
                    {{ vdata.goods.sku }}
                </div>
                <div class="goods_price_title">{{ vdata.goods.recommendation }}</div>
                <!-- <div class="goods_handle">
                    <el-input-number v-model="num" :min="1" :max="vdata.goods.goods_stock * 1" @change="handleChange" />
                </div> -->
                <div class="goods_bottom">
                    <el-button type="goon" size="large" @click="addOrder">立即购买</el-button>
                </div>
            </el-col>
            <el-col :span="8">
                <div class="good_img">
                    <img :src="vdata.goods.goodsBanner" alt="" srcset="" />
                </div>
                <!-- <div class="img_arr">
                    <img :src="vdata.goods.goods_banner" alt="" @click="changeImg(vdata.goods.goods_banner)" />
                </div> -->
            </el-col>
        </el-row>
        <el-row style="margin-top: 50px">
            <el-col :span="24">
                <!-- <div class="goods_description">
                    <el-tabs type="border-card" class="my-tabs">
                        <el-tab-pane label="商品评论">
                            <div class="goods-comment" v-for="(item, index) in 10" :key="index">
                                <div class="comment_body">
                                    <div class="comment_user">

                                        <div class="avatar">
                                            <img :src="vdata.goods.goodsBanner" alt="" />
                                        </div>
                                        <div class="user_time">
                                            <div class="user">地狱的吹雪 &nbsp;<span class="grey">评价</span></div>
                                            <div class="grey time">17小时前</div>
                                        </div>
                                    </div>
                                    <div class="comment_text">
                                        <div class="sku_name">{{ vdata.goods.goods_name }} &nbsp;<span
                                                class="grey">5星</span></div>
                                        <div class="grey comment_word">质量上乘，品质优越，值得信赖的产品</div>
                                    </div>
                                </div>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div> -->
                <div class="goods_description">
                    <div class="goods_description_title">
                        <div>商品评论</div>
                    </div>
                    <div class="goods-comment" v-for="(item, index) in 10" :key="index">
                        <div class="comment_body">
                            <div class="comment_user">

                                <div class="avatar">
                                    <img :src="vdata.goods.goodsBanner" alt="" />
                                </div>
                                <div class="user_time">
                                    <div class="user">地狱的吹雪 &nbsp;<span class="grey">评价</span></div>
                                    <div class="grey time">2024-04-22 12:00:00</div>
                                </div>
                            </div>
                            <div class="comment_text">
                                <div class="sku_name">{{ vdata.goods.goods_name }} &nbsp;<span class="grey stars">
                                        <qStars :numStar="3"></qStars>
                                    </span>
                                </div>
                                <div class="grey comment_word">质量上乘，品质优越，值得信赖的产品</div>
                            </div>
                        </div>
                    </div>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<style lang="scss" scoped>
.bofy {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 140px;
}

.good_img {
    height: 350px;
    width: 350px;

    img {
        @extend .good_img;
    }
}

.img_arr {
    display: flex;
    margin-top: 20px;
    height: 84px;
    width: 350px;
    overflow: auto;

    img {
        cursor: pointer;
        border: 1px #ddd solid;
        height: 80px;
        width: 80px;
        margin-right: 10px;
    }
}

.good_name {
    font-size: 24px;
    font-weight: bold;
    color: #2a2a2a;
    text-align: left;
    height: 40px;
    line-height: 40px;
}

.good_category {
    font-size: 20px;
    height: 30px;
    line-height: 30px;

    .goods_brand {
        font-weight: bold;
    }

    .category {
        color: #8a8787;
    }
}

.good_price_content {
    width: 100%;
    display: flex;
    align-items: baseline;
    color: #cf571f;
    margin-top: 20px;

    .price {
        font-size: 32px;
        font-weight: 400;
    }

    .small-text {
        font-size: 16px;
    }

    .goods_active {
        padding-left: 10px;
    }

}

.goods_price_title {
    font-size: 14px;
    padding: 10px 0 10px 10px;
    letter-spacing: 5px;
    color: #8a8787;
}

.goods_stock {
    height: 50px;
    font-size: 14px;
    display: flex;
    align-items: center;
}

.goods_rank {
    height: 40px;
    width: 100%;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 14px;
    color: #a2a2a2;

    div {
        width: 33%;
        text-align: center;

        span {
            color: #3497e5;
        }
    }

    div:nth-child(2) {
        border-left: 1px dashed #ccc;
        border-right: 1px dashed #ccc;
    }
}

.goods_service {
    display: flex;
    align-items: center;
    height: 40px;
    width: 100%;
    text-align: left;
}

.goods_pay {
    display: flex;
    align-items: center;
    height: 50px;
    width: 100%;
    text-align: left;
}

.goods_handle {
    display: flex;
    align-items: center;
}

.goods_bottom {
    margin-top: 20px;
    text-align: left;

    :deep(img) {
        max-width: 100%;
    }

    .el-button--goon.is-active,
    .el-button--goon:active {
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100));
        border-color: #3a3d3d;
        color: #fff;
    }

    .el-button--goon:focus,
    .el-button--goon:hover {
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100));
        border-color: #3a3d3d;
        color: #fff;
    }

    .el-button--goon {
        color: #FFF;
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100));
        border-color: #3a3d3d;
    }

}

.goods_description {
    width: 100%;


    .el-tabs--card>.el-tabs__header {
        border: none !important;
    }


    /* 去除灰色横条 */
    ::v-deep(.el-tabs__nav-wrap::after) {
        position: static !important;
    }

    /* 设置滑块颜色 */
    ::v-deep(.el-tabs__active-bar) {
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100)) !important;
    }

    ::v-deep(.el-tabs--border-card>.el-tabs__header .el-tabs__item.is-active) {
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100)) !important;
        color: #fff;
        font-weight: bold;
    }
}

.goods_description_title {
    height: 40px;
    // border-bottom: 2px #3497e5 solid;
    display: flex;

    div {
        padding: 0 20px;
        font-size: 14px;
        line-height: 40px;
        color: #fff;
        background: linear-gradient(rgb(75, 73, 73), rgb(107, 98, 100));
        // border-bottom-left-radius: 50px;
        // border-bottom-right-radius: 50px;
        width: 100%;
        text-align: center;
        margin: 0 auto;
    }
}

.goods-comment {
    min-height: 80px;
    border: 1px solid #3a3d3d;
    border-radius: 10px;
    margin: 10px;
    display: block;
    overflow: auto;

    .comment_body {
        margin: 10px;

        .comment_user {
            display: flex;
            height: 50px;

            .user_time {
                height: 25px;
                line-height: 25px;
                padding-left: 10px;
            }

            .avatar {
                width: 50px;
                /* 头像框的宽度 */
                height: 50px;
                /* 头像框的高度 */
                border: 3px solid #fff;
                /* 头像框的边框 */
                border-radius: 50%;
                /* 头像框的圆角 */
                overflow: hidden;
                /* 确保图片不会溢出头像框 */
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
                /* 头像框的阴影效果 */
                image-rendering: pixelated;

                /* 当图片缩放时，确保像素化效果 */
                img {
                    width: 100%;
                    /* 图片宽度匹配头像框宽度 */
                    height: 100%;
                    /* 图片高度匹配头像框高度 */
                }
            }


        }

        .comment_text {
            background-color: #cfdbe6;
            margin-top: 20px;
            padding-left: 30px;
            line-height: 25px;
            padding-top: 10px;
            padding-bottom: 10px;
            border-radius: 5px;

            .sku_name {
                color: #000;
                font-weight: bold;
                display: flex;
            }

            .stars {
                margin: auto 0;
            }

            .comment_word {}
        }
    }


}

.grey {
    color: #8a8787;
}

.goodsDescription {
    :deep(img) {
        max-width: 100%;
    }
}
</style>
